package com.zjhd.sealcutting.controller;

import com.zjhd.sealcutting.domain.ExhibitionInfo;
import com.zjhd.sealcutting.param.ExhibitionSearchQuery;
import com.zjhd.sealcutting.service.ExhibitionInfoService;
import com.zjhd.sealcutting.utils.OperLog;
import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import com.zjhd.sealcutting.vo.SearchResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO  展览管理
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/11/27 11:36
 */
@Api(value = "展览管理", tags = "展览管理")
@RequestMapping("/exhibition")
@RestController
public class ExhibitionInfoController {

    private final static Logger logger = LoggerFactory.getLogger(ExhibitionInfoController.class);

    @Autowired
    private ExhibitionInfoService exhibitionInfoService;

    @ApiOperation(value = "分页查询展览列表接口", notes = "分页查询展览列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型 (1:网络展览  2：线下展览)", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "exhibitionStatus", value = "展览状态 (1:征集作品中  2:展览中  3:已闭关 4:未发布)", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "页大小", defaultValue = "10", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "页码", defaultValue = "1", dataType = "String", paramType = "query")
    })
    @GetMapping("/queryExhibitionParamlist")
    public ResponseResult<SearchResult<ExhibitionInfo>> queryExhibitionParamlist(ExhibitionSearchQuery param){
        try{
            return ResultGenerator.genSuccessResult(exhibitionInfoService.queryExhibitionParamlist(param));
        }catch (Exception ex) {
            logger.error("分页查询展览列表接口失败", ex);
            return ResultGenerator.genFailResult("分页查询展览列表接口失败");
        }
    }

    @ApiOperation(value = "新增展览", notes = "新增展览接口")
    @PostMapping("/insertExhibition")
    @OperLog(operModul = "展览管理-新增展览",operType = "新增",operDesc = "新增展览")
    public ResponseResult insertExhibition(@RequestBody ExhibitionInfo exhibitionInfo){
        try{
            return ResultGenerator.genSuccessResult(exhibitionInfoService.insertExhibition(exhibitionInfo));
        }catch (Exception ex) {
            logger.error("新增展览接口失败", ex);
            return ResultGenerator.genFailResult("新增展览接口失败");
        }
    }

    @ApiOperation(value = "修改展览", notes = "修改展览接口")
    @PostMapping("/updateExhibition")
    @OperLog(operModul = "展览管理-修改展览",operType = "修改",operDesc = "修改展览")
    public ResponseResult updateExhibition(@RequestBody ExhibitionInfo exhibitionInfo){
        try{
            return ResultGenerator.genSuccessResult(exhibitionInfoService.updateExhibition(exhibitionInfo));
        }catch (Exception ex) {
            logger.error("修改展览接口失败", ex);
            return ResultGenerator.genFailResult("修改展览接口失败");
        }
    }

    @ApiOperation(value = "查询展览详情", notes = "查询展览详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "展览ID", dataType = "Long", paramType = "query")
    })
    @GetMapping("/queryByIdExhibition")
    @OperLog(operModul = "展览管理-查询展览",operType = "查询",operDesc = "查询展览详情")
    public ResponseResult queryByIdExhibition(Integer id){
        try{
            return ResultGenerator.genSuccessResult(exhibitionInfoService.queryByIdExhibition(id));
        }catch (Exception ex) {
            logger.error("查询展览详情接口失败", ex);
            return ResultGenerator.genFailResult("查询展览详情接口失败");
        }
    }

    @ApiOperation(value = "删除展览", notes = "删除展览接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "展览ID", dataType = "Long", paramType = "query")
    })
    @PostMapping("/delExhibition")
    @OperLog(operModul = "展览管理-删除展览",operType = "删除",operDesc = "删除展览")
    public ResponseResult delExhibition(@RequestParam(value = "id",defaultValue = "")Integer id){
        try{
            return ResultGenerator.genSuccessResult(exhibitionInfoService.delExhibition(id));
        }catch (Exception ex) {
            logger.error("删除展览接口失败", ex);
            return ResultGenerator.genFailResult("删除展览接口失败");
        }
    }

    @ApiOperation(value = "查询所有征集中的展览", notes = "查询所有征集中的展览接口")
    @GetMapping("/queryCentralizationExhibition")
    @OperLog(operModul = "展览管理-查询展览",operType = "查询",operDesc = "查询所有征集中的展览")
    public ResponseResult<List<ExhibitionInfo>> queryCentralizationExhibition(Integer userId){
        try{
            return ResultGenerator.genSuccessResult(exhibitionInfoService.queryCentralizationExhibition(userId));
        }catch (Exception ex) {
            logger.error("查询所有征集中的展览接口失败", ex);
            return ResultGenerator.genFailResult("查询所有征集中的展览接口失败");
        }
    }
}
